// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: "cloud1-2g73mn8d879c3-5b7cfc471b7"
})

let db = cloud.database({
  env: "cloud1-2g73mn8d879c3-5b7cfc471b7"
});

let usersTable = db.collection("users")
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const nickName = event.nickName || "(@-@)*(@-@)"
  let id = wxContext.OPENID;
  // md5(id)
  // 查询数据
  
  // ...  
  // 添加用户
  return await usersTable.add({
    data: {
      _id: id,
      name: nickName
    }
  })
}